<template>
	<view>
		<form @submit="formSubmit">
			<view class='addAddress'>
				<view class='list'>
					<!-- <view class='item acea-row row-between-wrapper'>
						<view class='name'>顾客编号</view>
						<input type='text' placeholder='请输入顾客编号' name='optAmount' :value="userAddress.optAmount"
							placeholder-class='placeholder'></input>
					</view> -->
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>充值金额(￥)</view>
						<input type='number' placeholder='请输入充值金额' name="optAmount" :value='userAddress.optAmount'
							placeholder-class='placeholder' pattern="\d*"></input>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>充值方式</view>
						<picker :value="userAddress.rechargeWay" name="rechargeWay" mode='selector' :range="rechargeMode"
							@change="bindPickerChange" range-key='name'>
							<view class="uni-input pickerView" v-if="userAddress.rechargeWay!==''">
								{{rechargeMode[userAddress.rechargeWay].name}}
							</view>
							<view v-else style="color:#ccc;">
								请选择充值方式
							</view>
						</picker>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>付款日期</view>
						<picker class="formInput" name="paymentTime" @change="bindPickerChange_PaymentDate" mode="date">
							<view class="uni-input pickerView" v-if="userAddress.paymentTime!==''">
								{{userAddress.paymentTime}}
							</view>
							<view v-else style="color:#ccc;">
								请选择付款日期
							</view>
						</picker>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>存款人姓名</view>
						<input placeholder='请输入存款人姓名或付款单据' name="rechargeName" :value='userAddress.rechargeName'
							placeholder-class='placeholder'></input>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>存款单号</view>
						<input type='number' placeholder='若无则填0' name="rechargeAccount"
							:value='userAddress.rechargeAccount' placeholder-class='placeholder' pattern="\d*"></input>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'>备注</view>
						<input type='text' placeholder='请填写备注' name='forMemberMemo' placeholder-class='placeholder'
							:value='userAddress.forMemberMemo'></input>
					</view>
				</view>

				<button class='keepBnt bg-color' form-type="submit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		getCashRechargeSubmit
	} from '@/api/directSelling.js'
	export default {
		data() {
			return {
				userAddress: {
					rechargeWay: "",
					paymentTime: ""
				},
				rechargeMode: [{ //是非选项
					name: "网银转账",
					value: "19"
				}, {
					name: "柜台交款",
					value: "12"
				}],
			};
		},
		onLoad(options) {},
		methods: {
			bindPickerChange(e) {
				this.userAddress.rechargeWay = e.target.value;
			},
			bindPickerChange_PaymentDate(e) {
				this.userAddress.paymentTime = e.target.value;
			},
			/**
			 * 提交用户添加地址
			 * 
			 */
			formSubmit: function(e) {
				let that = this,
					value = e.detail.value;
				value.rechargeWay=this.rechargeMode[this.userAddress.rechargeWay].value;
				value.type=1;
				console.log("value");
				console.log(value);
				if (!value.optAmount) return that.$util.Tips({
					title: '请填写充值金额'
				});
				if (!value.rechargeWay) return that.$util.Tips({
					title: '请选择充值方式'
				});
				
				if (!value.paymentTime) return that.$util.Tips({
					title: '请选择付款日期'
				});
				if (!value.rechargeName) return that.$util.Tips({
					title: '请填写存款人姓名'
				});
				if (!value.rechargeAccount) return that.$util.Tips({
					title: '请填写存款单号'
				});
				
				uni.showLoading({
					title: '保存中',
					mask: true
				})
				getCashRechargeSubmit(value).then(res => {
					if(res.meta.success==true){
						that.$util.Tips({
							title: '添加成功',
							icon: 'success'
						});
						setTimeout(()=>{
							uni.navigateTo({
								url: "/pages/electronicWallet/cashRecharge/RechargeList"
							});
						},400)
					}	
				}).catch(err => {
					return that.$util.Tips({
						title: err
					});
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.addAddress .list {
		background-color: #fff;
	}

	.addAddress .list .item {
		padding: 30rpx;
		border-top: 1rpx solid #eee;
	}

	.addAddress .list .item .name {
		width: 195rpx;
		font-size: 30rpx;
		color: #333;
	}

	.addAddress .list .item .address {
		// width: 412rpx;
		flex: 1;
		margin-left: 20rpx;
	}

	.addAddress .list .item input {
		width: 475rpx;
		font-size: 30rpx;
	}

	.addAddress .list .item .placeholder {
		color: #ccc;
	}

	.addAddress .list .item picker {
		width: 475rpx;
		height: 42rpx;
	}

	.addAddress .list .item picker .picker {
		width: 410rpx;
		font-size: 30rpx;
	}

	.addAddress .list .item picker .iconfont {
		font-size: 43rpx;
	}

	.addAddress .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.addAddress .default checkbox {
		margin-right: 15rpx;
	}

	.addAddress .keepBnt {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 50rpx auto;
		font-size: 32rpx;
		color: #fff;
	}

	.addAddress .wechatAddress {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 0 auto;
		font-size: 32rpx;
		color: #fe960f;
		border: 1px solid #fe960f;
	}
</style>
